//
//  HomeTiShiCell.m
//  CenturyCity
//
//  Created by beisheng03 on 2018/1/19.
//  Copyright © 2018年 beisheng. All rights reserved.
//

#import "HomeTiShiCell.h"
#import "HomeTiShiSubCell.h"
#import "AboutusController.h"
@interface HomeTiShiCell ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (weak, nonatomic) IBOutlet UIView *leftView;
@property (weak, nonatomic) IBOutlet UILabel *biaoTiLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomMargin;
@property (weak, nonatomic) IBOutlet UICollectionView *myCollectionView;
@property (weak, nonatomic) IBOutlet UIPageControl *pageContro;

@end

@implementation HomeTiShiCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.contentView.backgroundColor = viewBgGrey;
    
    self.bottomMargin.constant = 0;
    
    self.leftView.backgroundColor = colorWith(35, 122, 217);

    self.leftView.layer.cornerRadius = 1;

    self.leftView.layer.masksToBounds = YES;

    self.biaoTiLabel.font = MYFONT(16);
    
//    *pageIndicatorTintColor NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
//    @property(nullable, nonatomic,strong) UIColor *
    self.pageContro.pageIndicatorTintColor = viewBgGrey;
    self.pageContro.currentPageIndicatorTintColor = darkGray;

    
    [self.myCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([HomeTiShiSubCell class]) bundle:nil] forCellWithReuseIdentifier:[HomeTiShiSubCell identifierStr]];
    self.myCollectionView.delegate = self;
    self.myCollectionView.dataSource = self;
    self.myCollectionView.pagingEnabled = YES;
    
    self.myCollectionView.showsHorizontalScrollIndicator = NO;
    self.myCollectionView.showsVerticalScrollIndicator = NO;
    
    
    
    // Initialization code
}


- (void)setModels:(NSArray<HomeSubModel *> *)models{
    
    _models = models;
    self.pageContro.numberOfPages = _models.count;
    self.pageContro.currentPage = 0;

    [self.myCollectionView reloadData];
    
    
}



- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    if (self.models == nil) {
        return 0;
    } else {
        return self.models.count;
    }

}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    HomeTiShiSubCell *cell = (HomeTiShiSubCell *)[collectionView dequeueReusableCellWithReuseIdentifier:[HomeTiShiSubCell identifierStr] forIndexPath:indexPath];
    
    cell.model = self.models[indexPath.item];
    
    return cell;
    
}



- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    AboutusController *temp = [[AboutusController alloc]init];
    
    temp.urlString = self.models[indexPath.item].url;
    
    [self.viewController.navigationController pushViewController:temp animated:YES];
}


#pragma mark - 图片浏览器中UICollectionView代理方法

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
//    NSIndexPath *idex = self.myCollectionView.indexPathsForVisibleItems.firstObject;
    
    
    
//    NSLog(@"%f+++++++",scrollView.contentOffset.x);
    
    if (scrollView.contentOffset.x <  10) {
        
        self.pageContro.currentPage = 0;

    } else if (scrollView.contentOffset.x < KScreenW + 10) {
        
        self.pageContro.currentPage = 1;
        
    }else{
        
        self.pageContro.currentPage = 2;
    }
    
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
